<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>location地址栏对象</title>
    <style>
        p {
            text-align: center;
        }

        span {
            color: red;
        }
    </style>
</head>

<body>
    <p>
        注册成功！<span id="time">5</span>秒之后自动跳转到首页...
    </p>
    <script type="text/javascript">
        let time = document.getElementById("time");
        let t = 5;//给定初始时间
        let daojishi = window.setInterval(function () {
            //开启定时器
            time.innerHTML = t;
            //将输出内容改变
            t--;
            //判断时间值是否改变到0了
            if (t === 0) {
                //时间到了,跳转到首页并结束定时器
                location.href = "index.html";
                clearInterval(daojishi);
            }
        }, 1000);
    </script>
</body>

</html>